﻿function AzureOnlineTableRecordDeleteDetailsView(context) {

    var self = this;

    var spinner = new SpinnerModel();

    var dispatcher = $({});

    var table = context.tables.table;

    var records = context.tables.records;

    var rec = ko.observable(null);

    function init(record) {
        rec(record);
    }

    function remove() {
        var tableName = table();
        var record = rec();
        var api = context.api();
        spinner.enter();
        api.tables.deleteEntity({
            table: tableName,
            partitionKey: record.partitionKey(),
            rowKey: record.rowKey(),
            success: function () {
                spinner.leave();
                records.remove(record);
                dispatcher.trigger('success');
            },
            error: function () {
                spinner.leave();
                return 'notify';
            }
        });
    }

    function addOnSuccess(handler) {
        dispatcher.bind('success', handler);
    };

    self.init = init;
    self.table = table;
    self.record = rec;
    self.remove = remove;
    self.addOnSuccess = addOnSuccess;

}